﻿using System;
using Castle.ActiveRecord;

namespace Hadlow.Jobvertizer.Models
{
    [ActiveRecord]
    public class Role : Entity
    {
        string name;

        [Property]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public override string ToString()
        {
            return name;
        }

        // allowed roles. These must match the data in table Role
        public static Role Administrator { get { return new Role() { Id = 1, Name = "Administrator" }; } }
        public static Role Poster { get { return new Role() { Id = 2, Name = "Poster" }; } }
        public static Role Candidate { get { return new Role() { Id = 3, Name = "Candidate" }; } }
        public static Role Guest { get { return new Role() { Id = 4, Name = "Guest" }; } }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (!(obj is Role)) return false;
            return this.Id == ((Role)obj).Id;
        }

        public static bool operator ==(Role role1, Role role2)
        {
            return role1.Equals(role2);
        }

        public static bool operator !=(Role role1, Role role2)
        {
            return !(role1 == role2);
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }
    }
}
